package com.zjdiepu.www.rest.api.yw;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Id;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.ParentModel;
import com.zjdiepu.www.base.enums.status.BusiStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.LessInformationStatus;
import com.zjdiepu.www.base.enums.status.PhoneStatus;
import com.zjdiepu.www.base.enums.status.PickCarStatus;
import com.zjdiepu.www.base.enums.status.RefundDepositStatus;
import com.zjdiepu.www.base.enums.type.BusinessExtrasCodeType;
import com.zjdiepu.www.base.enums.type.BusinessExtrasType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.ibiz.dh.IDhDepositMoneyService;
import com.zjdiepu.www.ibiz.dz.IDzPickCarService;
import com.zjdiepu.www.ibiz.other.IOtherAuditInfoService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessExtrasService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.model.dh.dto.DhDepositMoney;
import com.zjdiepu.www.model.dz.dto.DzPickCar;
import com.zjdiepu.www.model.other.dto.OtherAuditInfo;
import com.zjdiepu.www.model.other.ext.OtherAuditInfoExt;
import com.zjdiepu.www.model.yw.dto.YwBusinessExtras;
import com.zjdiepu.www.model.yw.response.ShenPiLiuZhuanResponse;
import com.zjdiepu.www.model.yw.response.SplzResponse;
import com.zjdiepu.www.model.yw.response.YwBusinessBaseResponse;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;

/**
 * 业务信息Controller层<br/>
 * @author xiongxiaotun<br/>
 * @time 2017年04月24日 14时43分<br/>
 * @since 1.0<br/>
 */
@RestController
@RequestMapping(value= "YwGeneralController", produces="application/json;charset=UTF-8", method=RequestMethod.POST)
@Api(tags = {"业务信息"}, produces="application/json;charset=UTF-8")
public class YwGeneralController extends BaseController {
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
    private TokenUserHelper tokenUserHelper;
	@Resource
	private IYwBusinessService ywBusinessService;
	@Resource
	private IDzPickCarService dzPickCarService;
	@Resource
	private IOtherAuditInfoService otherAuditInfoService;
	@Resource
	private IDhDepositMoneyService dhDepositMoneyService;
	@Resource
	private IYwBusinessExtrasService ywBusinessExtrasService;
	/**
     * @author xiongxiaotun <br/>
     * @Title: splz <br/>
     * @Description: 审批流转 <br/>
     * @param parentModel
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "审批流转",response = ShenPiLiuZhuanResponse.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping("auditInfo")
    public ApiResponse auditInfo(@Validated(Id.class) @RequestBody ParentModel parentModel){
    	tokenUserHelper.getUser();
    	ShenPiLiuZhuanResponse shenPiLiuZhuanResponse = new ShenPiLiuZhuanResponse();
    	String busiId = parentModel.getId();
    	shenPiLiuZhuanResponse.setBusiId(busiId);
    	
    	YwBusinessExtras ywBusinessExtrasParam = new YwBusinessExtras();
		ywBusinessExtrasParam.setBusiId(busiId);
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.ADD_GPS.getCode());
		ywBusinessExtrasParam.setTypeExtras(BusinessExtrasType.AUDIT.getCode());
		ywBusinessExtrasParam.setDpStatus(DpStatus.NORMAL.getCode());
		
		YwBusinessExtras gps = ywBusinessExtrasService.selectRefined(ywBusinessExtrasParam);
		Integer gpsNum = 0;
		if(null != gps) {
			String valueExtras = gps.getValueExtras();
			try {
				gpsNum = StringUtils.isBlank(valueExtras) ? 0 : Integer.parseInt(valueExtras);
			} catch(Exception e) {
				logger.error("格式化GPS个数错误，valueExtras is {}.", valueExtras, e);
			}
		}
		shenPiLiuZhuanResponse.setGps(gpsNum);
		
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.ADD_GEPOSIT.getCode());
		YwBusinessExtras yajin = ywBusinessExtrasService.selectRefined(ywBusinessExtrasParam);
		Double yajinNum = 0.0;
		if(null != yajin) {
			String valueExtras = yajin.getValueExtras();
			try {
				yajinNum = StringUtils.isBlank(valueExtras) ? 0 : Double.parseDouble(valueExtras);
			} catch(Exception e) {
				logger.error("格式化征信押金错误，valueExtras is {}.", valueExtras, e);
			}
		}
		shenPiLiuZhuanResponse.setCreditDeposit(yajinNum);
		
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.FLEXIBLECHARGE.getCode());
		YwBusinessExtras sfbt = ywBusinessExtrasService.selectRefined(ywBusinessExtrasParam);
		Double sfbtNum = 0.0;
		if(null != sfbt)
		{
			String valueExtras = sfbt.getValueExtras();
			try {
				sfbtNum = StringUtils.isBlank(valueExtras) ? 0 : Double.parseDouble(valueExtras);
			} catch(Exception e) {
				logger.error("格式化收费变通错误，valueExtras is {}.", valueExtras, e);
			}
		}
		shenPiLiuZhuanResponse.setChargeChange(sfbtNum);
		
		ywBusinessExtrasParam.setCodeExtras(BusinessExtrasCodeType.IS_SPECIAL_ORDER.getCode());
		YwBusinessExtras tsdd = ywBusinessExtrasService.selectRefined(ywBusinessExtrasParam);
		boolean tsddB = false;
		if(null != tsdd)
		{
			String valueExtras = tsdd.getValueExtras();
			tsddB = "1".equals(valueExtras);
		}
		shenPiLiuZhuanResponse.setSpecialOrder(tsddB);
		
		OtherAuditInfoExt otherAuditInfoExt = new OtherAuditInfoExt();
		otherAuditInfoExt.setBaseWhere();
		otherAuditInfoExt.withOutPage();
		otherAuditInfoExt.setBusiId(busiId);
		otherAuditInfoExt.setOrderSql(" `CREATED` DESC");
		List<OtherAuditInfo> otherAuditInfos = otherAuditInfoService.selectByExt(otherAuditInfoExt);
		shenPiLiuZhuanResponse.setOtherAuditInfos(otherAuditInfos);
    	
    	return ApiResponse.success(shenPiLiuZhuanResponse);
    }
	
	/**
     * @author xiongxiaotun <br/>
     * @Title: splz <br/>
     * @Description: 审批流转 <br/>
     * @param parentModel
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "审批流转",response = YwBusinessBaseResponse.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping("splz")
    public ApiResponse splz(@Validated(Id.class) @RequestBody ParentModel parentModel){
    	tokenUserHelper.getUser();
    	String busiId = parentModel.getId();
    	YwBusinessDetail ywBusinessDetail = ywBusinessService.getMultiById(busiId);
    	if(null == ywBusinessDetail) {
    		return ApiResponse.fail(ResultFlagType.MISSING.getCode(), "业务记录不存在或已被删除");
    	}
    	
    	List<SplzResponse> splzResponses = new ArrayList<SplzResponse>();
    	
    	SplzResponse zxcx = new SplzResponse();
    	zxcx.setCode("zxcx");
    	zxcx.setBusiStatus(0);
    	zxcx.setName("征信查询");
    	zxcx.setSort(10010);
    	splzResponses.add(zxcx);
    	
    	SplzResponse zllr = new SplzResponse();
    	zllr.setCode("zllr");
    	zllr.setBusiStatus(10);
    	zllr.setName("资料登记");
    	zllr.setSort(10020);
    	splzResponses.add(zllr);
    	
    	SplzResponse csdcs = new SplzResponse();
    	csdcs.setCode("csdcs");
    	csdcs.setBusiStatus(30);
    	csdcs.setLastBusiStatus(9010);
    	csdcs.setName("初审一审");
    	csdcs.setSort(10030);
    	splzResponses.add(csdcs);
    	
    	SplzResponse csdzs = new SplzResponse();
    	csdzs.setCode("csdzs");
    	csdzs.setBusiStatus(40);
    	csdzs.setLastBusiStatus(9020);
    	csdzs.setName("初审二审");
    	csdzs.setSort(10040);
    	splzResponses.add(csdzs);
    	
    	SplzResponse escbs = new SplzResponse();
    	escbs.setCode("escbs");
    	escbs.setBusiStatus(200);
    	escbs.setName("二手车过户补审");
    	escbs.setSort(10050);
    	splzResponses.add(escbs);
    	
    	SplzResponse lstdbs = new SplzResponse();
    	lstdbs.setCode("lstdbs");
    	lstdbs.setName("绿色通道补审");
    	lstdbs.setSort(10060);
    	splzResponses.add(lstdbs);
    	
    	SplzResponse zlbqbs = new SplzResponse();
    	zlbqbs.setCode("zlbqbs");
    	zlbqbs.setName("资料补齐补审");
    	zlbqbs.setSort(10070);
    	splzResponses.add(zlbqbs);
    	
    	SplzResponse dsys = new SplzResponse();
    	dsys.setCode("dsys");
    	dsys.setName("电审一审");
    	dsys.setSort(10080);
    	splzResponses.add(dsys);
    	
    	SplzResponse dses = new SplzResponse();
    	dses.setCode("dses");
    	dses.setName("电审二审");
    	dses.setSort(10090);
    	splzResponses.add(dses);
    	
    	SplzResponse zsys = new SplzResponse();
    	zsys.setCode("zsys");
    	zsys.setBusiStatus(70);
    	zsys.setLastBusiStatus(9030);
    	zsys.setName("资审一审");
    	zsys.setSort(10100);
    	splzResponses.add(zsys);
    	
    	SplzResponse zses = new SplzResponse();
    	zses.setCode("zses");
    	zses.setBusiStatus(80);
    	zses.setLastBusiStatus(9040);
    	zses.setName("资审二审");
    	zses.setSort(10110);
    	splzResponses.add(zses);
    	
    	SplzResponse fkjl = new SplzResponse();
    	fkjl.setCode("fkjl");
    	fkjl.setBusiStatus(90);
    	fkjl.setLastBusiStatus(9050);
    	fkjl.setName("风控经理");
    	fkjl.setSort(10120);
    	splzResponses.add(fkjl);
    	
    	SplzResponse fkzj = new SplzResponse();
    	fkzj.setCode("fkzj");
    	fkzj.setBusiStatus(100);
    	fkzj.setLastBusiStatus(9060);
    	fkzj.setName("风控总监");
    	fkzj.setSort(10130);
    	splzResponses.add(fkzj);
    	
    	SplzResponse sqdz = new SplzResponse();
    	sqdz.setCode("sqdz");
    	sqdz.setName("申请垫资");
    	sqdz.setSort(10140);
    	splzResponses.add(sqdz);
    	
    	SplzResponse cwyshz = new SplzResponse();
    	cwyshz.setCode("cwyshz");
    	cwyshz.setCw(100);
    	cwyshz.setName("财务一审核中");
    	cwyshz.setSort(10150);
    	splzResponses.add(cwyshz);
    	
    	SplzResponse cweshz = new SplzResponse();
    	cweshz.setCode("cweshz");
    	cweshz.setCw(150);
    	cweshz.setName("财务二审核中");
    	cweshz.setSort(10160);
    	splzResponses.add(cweshz);
    	
    	SplzResponse cwfk = new SplzResponse();
    	cwfk.setCode("cwfk");
    	cwfk.setCw(200);
    	cwfk.setName("财务放款");
    	cwfk.setSort(10170);
    	splzResponses.add(cwfk);
    	
    	SplzResponse tcqr = new SplzResponse();
    	tcqr.setCode("tcqr");
    	tcqr.setName("新车提车审核");
    	tcqr.setSort(10180);
    	splzResponses.add(tcqr);
    	
    	SplzResponse clzlfs = new SplzResponse();
    	clzlfs.setCode("clzlfs");
    	clzlfs.setName("车辆资料复审");
    	clzlfs.setSort(10190);
    	splzResponses.add(clzlfs);
    	
    	SplzResponse cpdj = new SplzResponse();
    	cpdj.setCode("cpdj");
    	cpdj.setName("车牌登记");
    	cpdj.setSort(10200);
    	splzResponses.add(cpdj);
    	
    	SplzResponse dyqr = new SplzResponse();
    	dyqr.setCode("dyqr");
    	dyqr.setName("抵押确认");
    	dyqr.setSort(10210);
    	splzResponses.add(dyqr);
    	
    	SplzResponse tyjcs = new SplzResponse();
    	tyjcs.setCode("tyjcs");
    	tyjcs.setName("退押金催收审核");
    	tyjcs.setSort(10220);
    	splzResponses.add(tyjcs);
    	
    	SplzResponse tyjxb = new SplzResponse();
    	tyjxb.setCode("tyjxb");
    	tyjxb.setName("退押金续保审核");
    	tyjxb.setSort(10230);
    	splzResponses.add(tyjxb);
    	
    	SplzResponse td = new SplzResponse();
    	td.setCode("td");
    	td.setMin(9010);
    	td.setMax(9800);
    	td.setName("退单");
    	td.setSort(10240);
    	splzResponses.add(td);
    	
    	SplzResponse tk = new SplzResponse();
    	tk.setCode("tk");
    	tk.setBusiStatus(9810);
    	tk.setName("退贷");
    	tk.setSort(10250);
    	splzResponses.add(tk);
    	
    	SplzResponse aqhk = new SplzResponse();
    	aqhk.setCode("aqhk");
    	aqhk.setName("按期还款");
    	aqhk.setSort(10260);
    	splzResponses.add(aqhk);
    	
    	SplzResponse jq = new SplzResponse();
    	jq.setCode("jq");
    	jq.setBusiStatus(9999);
    	jq.setName("结清");
    	jq.setSort(10270);
    	splzResponses.add(jq);
    	
    	/*
    	 * 提车状态
    	 * 0：未提车
    	 * 1：提车中
    	 * 2：已提车
    	 * 3：二手车
    	 */
    	Integer pickCarStatus = 0; //未提车
    	String carType = ywBusinessDetail.getCarType();
    	Integer busiStatus = ywBusinessDetail.getBusiStatus();
    	Date pickCarTime = ywBusinessDetail.getPickCarTime();
    	if("01".equals(carType)) {
    		if(BusiStatus.SHEN_PI_WAN_CHENG.getCode() <= busiStatus) {
    			DzPickCar dzPickCar = new DzPickCar();
    			dzPickCar.setDpStatus(DpStatus.NORMAL.getCode());
    			dzPickCar.setBusiId(busiId);
    			DzPickCar dzPickCar_ = dzPickCarService.selectRefined(dzPickCar);
    			if(null == dzPickCar_) {
    				pickCarStatus = 0;
    			} else {
    				Integer pickCarStatus_ = dzPickCar_.getPickCarStatus();
    				if(PickCarStatus.YI_SHEN_HE.getCode() == pickCarStatus_ && pickCarTime != null){
    					pickCarStatus = 2; //已经审核：通过
    				}/* else if(PickCarStatus.YI_SHEN_HE.getCode()==pickCarStatus_ && pickCarTime == null){
    					pickCarStatus = 2; //已经审核：不通过
	    			}*/ else {
	    				pickCarStatus = 1; //待审核
	    			}
    			}
    			
    		}
    	} else {
    		pickCarStatus = 3; //二手车
    	}
    	
    	/*
    	 * 车牌登记状态
    	 * 0：未提车
    	 * 1：提车中
    	 * 2：已提车
    	 */
    	Integer registrationPlatesStatus = 0; //未登记
    	Date licensePlateTime = ywBusinessDetail.getLicensePlateTime();
    	if(busiStatus >=  BusiStatus.SHEN_PI_WAN_CHENG.getCode() && busiStatus <= BusiStatus.YIN_HANG_YI_FANG_KUAN.getCode()) {
    		if(licensePlateTime == null){
    			registrationPlatesStatus = 1;//登记中
    		} else {
    			registrationPlatesStatus = 2;//已登记
    		}
    	}
    	
    	/*
    	 * 抵押状态
    	 * 0：未抵押
    	 * 1：抵押中
    	 * 2：已抵押
    	 */
    	Integer pledgeStatus = 0; //未抵押
    	Date pledgeTime = ywBusinessDetail.getPledgeTime();
    	if(busiStatus >=  BusiStatus.SHEN_PI_WAN_CHENG.getCode() && busiStatus <= BusiStatus.YIN_HANG_YI_FANG_KUAN.getCode()) {
    		if(pledgeTime == null){
    			pledgeStatus = 1;//抵押中
    		} else {
    			pledgeStatus = 2;//已抵押
    		}
    	}

    	/*
    	 * 按期还款状态
    	 * 0：不需要还款
    	 * 1：还款中
    	 */
    	Integer lendingStatus = 0; //未抵押
    	Date timeLending = ywBusinessDetail.getTimeLending();
		if(timeLending == null){
			pledgeStatus = 0;//不需要还款
		} else {
			pledgeStatus = 1;//还款中
		}
		
		/*
    	 * 退押金状态
    	 * 0：没有退押金审核
    	 * 1：退押金审核中
    	 * 2：退押金催收审核
    	 * 3：退押金续保审核
    	 * 4：退押金审核完成
    	 */
    	Integer depositMoneyStatus = 0; //未抵押
    	DhDepositMoney dhDepositMoney = new DhDepositMoney();
    	dhDepositMoney.setDpStatus(DpStatus.NORMAL.getCode());
    	dhDepositMoney.setBusiId(busiId);
    	DhDepositMoney dhDepositMoney_ = dhDepositMoneyService.selectRefined(dhDepositMoney);
    	if(dhDepositMoney_ == null){
    		depositMoneyStatus = 0;//没有退押金审核
    	} else {
    		Integer statusRefundDeposit = dhDepositMoney_.getStatusRefundDeposit();
    		if(RefundDepositStatus.YI_SHEN_QIN.getCode().equals(statusRefundDeposit)) {
    			depositMoneyStatus = 1;//退押金审核中
    		} else if(RefundDepositStatus.CUI_SHOU_YI_SHEN_HE.getCode().equals(statusRefundDeposit)){
    			depositMoneyStatus = 2;//催收已审核
    		} else if(RefundDepositStatus.XU_BAO_YI_SHEN_HE.getCode().equals(statusRefundDeposit)){
    			depositMoneyStatus = 3;//续保已审核
    		} else if(RefundDepositStatus.YI_TUI_KUAN.getCode().equals(statusRefundDeposit)){
    			depositMoneyStatus = 4;//已退款
    		}
    	}
    	
    	Integer lastBusiStatus = 0;
    	OtherAuditInfoExt otherAuditInfoExt = new OtherAuditInfoExt();
    	otherAuditInfoExt.setBaseWhere();
    	otherAuditInfoExt.setRows(1);
    	otherAuditInfoExt.setBusiId(busiId);
    	otherAuditInfoExt.setAuditStatusValueType("BusiStatus");
    	otherAuditInfoExt.setOrderSql("`CREATED` DESC");
    	otherAuditInfoExt.setWhereSql("`AUDIT_STATUS_VALUE` <= " + BusiStatus.TUI_DAI.getCode());
    	List<OtherAuditInfo> otherAuditInfos = otherAuditInfoService.selectByExt(otherAuditInfoExt);
    	if(CollectionUtils.isNotEmpty(otherAuditInfos)) {
    		lastBusiStatus = otherAuditInfos.get(0).getAuditStatusValue();
    	}
    	Integer phoneStatus = ywBusinessDetail.getPhoneStatus();
//    	null、0：未审批， 1：审批中，2：已审批
    	if(PhoneStatus.PHONE_1_ING.getCode().equals(phoneStatus)) {
    		dsys.setStatus(1);
    		dses.setStatus(0);
    	} else if(PhoneStatus.PHONE_2_ING.getCode().equals(phoneStatus)){
    		dsys.setStatus(2);
    		dses.setStatus(1);
    	} else if(PhoneStatus.PHONE_2_SUCCESS.getCode().equals(phoneStatus)){
    		dsys.setStatus(2);
    		dses.setStatus(2);
    	} else if(PhoneStatus.PHONE_1_FAIL.getCode().equals(phoneStatus)){
    		dsys.setStatus(2);
    		dses.setStatus(0);
    	} else if(PhoneStatus.PHONE_2_FAIL.getCode().equals(phoneStatus)){
    		dsys.setStatus(2);
    		dses.setStatus(2);
    	} else {
    		dsys.setStatus(0);
    		dses.setStatus(0);
    	}
//    	null、0：未审批， 1：审批中，2：已审批
 		 if(pickCarStatus == 0) {
 			tcqr.setStatus(0);
 		 } else if(pickCarStatus == 1) {
 			tcqr.setStatus(1);
 		 } else if(pickCarStatus == 2) {
 			tcqr.setStatus(2);
 		 } else if(pickCarStatus == 3) { //二手车
 			tcqr.setStatus(0);
 		 }
 		 
 		 //车辆资料复审
//     	null、0：未审批， 1：审批中，2：已审批
 		 if("02".equals(carType)) {
 			 if(busiStatus == 210) {
 				clzlfs.setStatus(1);
 			 } else if(busiStatus < 210) {
 				clzlfs.setStatus(0);
 			 } else if(busiStatus >= 9000){
 				if(lastBusiStatus <= 210) {
 					clzlfs.setStatus(0);
	 			 } else {
	 				clzlfs.setStatus(2);
	 			 }
 			 } else {
 				clzlfs.setStatus(2);
 			 }
 		 } else if("01".equals(carType)) {
 			if(busiStatus == 400) {
 				clzlfs.setStatus(1);
 			 } else if(busiStatus < 400) {
 				clzlfs.setStatus(0);
 			 } else if(busiStatus >= 9000) {
 				if(lastBusiStatus <= 400) {
 					clzlfs.setStatus(0);
	 			 } else {
	 				clzlfs.setStatus(2);
	 			 }
 			 } else {
 				clzlfs.setStatus(2);
 			 }
 		 }
//      	null、0：未审批， 1：审批中，2：已审批
 		 if(pickCarStatus == 0) {
 			tcqr.setStatus(0);
 		 } else if(pickCarStatus == 1) {
 			tcqr.setStatus(1);
 		 } else if(pickCarStatus == 2) {
 			tcqr.setStatus(2);
 		 } else if(pickCarStatus == 3) { //二手车
 			tcqr.setStatus(0);
 		 }
//   	null、0：未审批， 1：审批中，2：已审批
 		 if(registrationPlatesStatus == 0) {
 			cpdj.setStatus(0);
 		 } else if(registrationPlatesStatus == 1) {
 			cpdj.setStatus(1);
 		 } else if(registrationPlatesStatus == 2) {
 			cpdj.setStatus(2);
 		 }
 		 
 		 if(pledgeStatus == 0) {
 			dyqr.setStatus(0);
 		 } else if(pledgeStatus == 1) {
 			dyqr.setStatus(1);
 		 } else if(pledgeStatus == 2) {
 			dyqr.setStatus(2);
 		 }
 		 
 		 if(lendingStatus == 0) {
 			aqhk.setStatus(0);
 		 } else if(lendingStatus == 1) {
 			aqhk.setStatus(1);
 		 }
 		 
 		 if(depositMoneyStatus == 0) {
 			tyjcs.setStatus(0);
 			tyjxb.setStatus(0);
 		 } else if(depositMoneyStatus == 1) {
 			tyjcs.setStatus(1);
 			tyjxb.setStatus(1);
 		 } else if(depositMoneyStatus == 2) {
 			tyjcs.setStatus(2);
 			tyjxb.setStatus(1);
 		 } else if(depositMoneyStatus == 3) {
 			tyjcs.setStatus(1);
 			tyjxb.setStatus(2);
 		 } else if(depositMoneyStatus == 4) {
 			tyjcs.setStatus(2);
 			tyjxb.setStatus(2);
 		 }
 		 
 		 Integer lessInformationStatus = ywBusinessDetail.getLessInformationStatus();
 		 if(lessInformationStatus == null) {
 			zlbqbs.setStatus(0);
 		 } else if(LessInformationStatus.QIAN_ZI_LIAO.getCode().equals(lessInformationStatus)){
 			zlbqbs.setStatus(1);
 		 } else if(LessInformationStatus.ZI_LIAO_QI_QUAN.getCode().equals(lessInformationStatus)){
 			zlbqbs.setStatus(0);
 		 } else if(LessInformationStatus.ZI_LIAO_YI_BU_QI.getCode().equals(lessInformationStatus)){
 			zlbqbs.setStatus(2);
 		 }
 		 if(lastBusiStatus == 9070) {
 			zlbqbs.setStatus(2);
 		 }
 		 
 		String channelType = ywBusinessDetail.getChannelType();
 		Integer channelStatus = ywBusinessDetail.getChannelStatus();
 		 if(channelType == null) {
 			lstdbs.setStatus(0);
 		 } else if ("50".equals(channelType)) {
 			 if(channelStatus == null) {
 				lstdbs.setStatus(0);
 			 } else if("10".equals(channelType)) {
 				lstdbs.setStatus(1);
 			 } else if("20".equals(channelType)) {
 				lstdbs.setStatus(2);
 			 } else if("90".equals(channelType)) {
 				lstdbs.setStatus(2);
 			 }
 		 } else {
 			lstdbs.setStatus(0);
 		 }
//    	null、0：未审批， 1：审批中，2：已审批
 		 Integer addedStatus1 = ywBusinessDetail.getAddedStatus1();
 		 for(SplzResponse splzResponse : splzResponses) {
 			 Integer cw = splzResponse.getCw();
 			 if(null != cw) {
 				if(cw < addedStatus1) {
 					splzResponse.setStatus(2);
 				} else if(cw == addedStatus1) {
 					splzResponse.setStatus(1);
 				} else {
 					splzResponse.setStatus(0);
 				} 
 			 }
 			 
 			Integer equal = splzResponse.getBusiStatus();
 			Integer second = splzResponse.getLastBusiStatus();
 			Integer min = splzResponse.getMin();
 			Integer max = splzResponse.getMax();
 			
 			if(null != equal && equal >= 9810 && null != lastBusiStatus) { //弃贷，退贷等
	 			if(equal == busiStatus) {
	 				splzResponse.setStatus(2);
				} else {
					splzResponse.setStatus(0);
				}
	 		} else if(null != equal){
	 			if(null != second && lastBusiStatus > 9000 ) { //审核不通过等结束了的订单
	 				if(second <= lastBusiStatus) {
	 					splzResponse.setStatus(2);
					} else {
						splzResponse.setStatus(0);
					}
	 			} else {  //还没有结束的订单
			 		if(equal < busiStatus) {
			 			splzResponse.setStatus(2);
					} else if(equal == busiStatus) {
						splzResponse.setStatus(1);
					} else {
						splzResponse.setStatus(0);
					}
	 			}
	 		}
	 		
	 		if(null != min && null != max && max <= 9810 && null != lastBusiStatus) {
 				 if(lastBusiStatus < min) {
 					splzResponse.setStatus(0);
 				 } else if(lastBusiStatus >= min && lastBusiStatus <= max){
 					if(lastBusiStatus > 9000) {
 						splzResponse.setStatus(2);
 					} else {
 						splzResponse.setStatus(1);
 					}
 				 } else {
 					splzResponse.setStatus(2);
 				 }
	 		} else {
	 			if(busiStatus < min) {
	 				splzResponse.setStatus(0);
 				 } else if(busiStatus >= min){
 					splzResponse.setStatus(1);
 				 }
	 		}
 			 
 		 }
 		if("01".equals(carType)) { //新车时，二手车过户审核重置为空
 			escbs.setStatus(0);
		}
			 
 		if(null != addedStatus1) {
 			if(addedStatus1 <= 20) {
 				sqdz.setStatus(0);
	 		 } else if(addedStatus1 >= 100){
	 			if(addedStatus1 == 400) {
	 				sqdz.setStatus(1);
		 			cwyshz.setStatus(0);
		 			cweshz.setStatus(0);
		 			cwfk.setStatus(0);
	 			} else {
	 				sqdz.setStatus(2);
	 			}
	 		 }
 		 } else {
 			sqdz.setStatus(0);
 		 }
    	
    	
//    	showSplz(phoneStatus, busiStatus,channelType, channelStatus, lessInformationStatus,addedStatus1, pickCarStatus, registrationPlatesStatus, pledgeStatus, lendingStatus, depositMoneyStatus,carType,lastBusiStatus)
    	Collections.sort(splzResponses);
        return ApiResponse.success(splzResponses);
    }
    
}





